/**
 * 
 */
package com.orcwar.engine.tile;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;

import com.orcwar.engine.OWTile;
import com.orcwar.enums.OWAttackTileTypeEnum;

/**
 * This class is used to store information about a specific tile when computing
 * the tiles on which a unit can attack. The additional attributes used are :
 *  - type, which can be either ATTACKABLE if the unit can attack it, or 
 *  MANDATORY_NOT_UNIT and MANDATORY_NOT_WALL if it's only a tile that needs to
 *  respect a certain constraint to that the unit can attack another tile.
 *  - linkedTiles, which are the other tiles on which the unit will attack if it
 *  attacks this one.
 * @author Callil
 *
 */
public class OWAttackTile extends OWTile {

	private EnumSet<OWAttackTileTypeEnum> type;
	private OWAttackTile[] linkedTiles;
	
	/**
	 * @param id
	 * @param x
	 * @param y
	 */
	public OWAttackTile(int id, int x, int y) {
		super(id, x, y);
		// TODO Auto-generated constructor stub
	}

	/**
	 * Not used
	 */
	public OWAttackTile(OWTile tile, OWAttackTileTypeEnum... type) {
		super(tile);
		if (type.length >0) {
			this.setType(EnumSet.of(type[0], type));
		}
	}

	/**
	 * Create an attack tile basing on a tile and at least one type.
	 * @param tile the tile to copy
	 * @param types the types to set
	 * @return a OWAttackTile
	 */
	public static OWAttackTile create(OWTile tile, OWAttackTileTypeEnum... types) {
		OWAttackTile result = null;
		if (tile != null) {
			result = new OWAttackTile(tile, types);
		}
		return result;
	}
	
	/**
	 * Create an attack tile basing on a tile and a list of linked tiles.
	 * @param tile the tile to copy
	 * @param linkedTiles the linked tiles that will be attacked if a unit attacks
	 * this tile.
	 * @return a OWAttackTile
	 */
	public static OWAttackTile create(OWTile tile, OWAttackTile... linkedTiles) {
		OWAttackTile result = null;
		if (tile != null) {
			result = new OWAttackTile(tile, OWAttackTileTypeEnum.ATTACKABLE);
			result.setLinkedTiles(linkedTiles);
		}
		return result;
	}
	
	
	// GETTERS / SETTERS

	/**
	 * @return the type
	 */
	public EnumSet<OWAttackTileTypeEnum> getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(EnumSet<OWAttackTileTypeEnum> type) {
		this.type = type;
	}

	/**
	 * @return the linkedTile ids
	 */
	public List<Integer> getLinkedTilesIds() {
		if (linkedTiles == null) return null;
		
		List<Integer> result = new ArrayList<Integer>();
		for (OWAttackTile attackTile : linkedTiles) {
			if (attackTile != null) result.add(attackTile.getId());
		}
		return result;
	}
	
	/**
	 * @return the linkedTiles
	 */
	public OWAttackTile[] getLinkedTiles(){
		return linkedTiles;
	}

	/**
	 * @param linkedTiles the linkedTiles to set
	 */
	public void setLinkedTiles(OWAttackTile[] linkedTiles) {
		this.linkedTiles = linkedTiles;
	}
	

}
